	/*kungeekui v1.0  基于jquery 与 bootstrap*/
	(function($) { //插件
	    if (window.kungeekui) return;
	    var kungeekui = {};
	    // ---------------------------模态框
	    kungeekui.modalDom = $('<div class="modal animated" id="kungeek-modal" tabindex="-1" role="dialog">' +
	        '<div class="modal-dialog" role="document">' +
	        '<div class="modal-content">' +
	        '<div class="modal-header">' +
	        '<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>' +
	        '<h4 class="modal-title"></h4>' +
	        '</div>' +
	        '<div class="modal-body">' +
	        '</div>' +
	        '<div class="clearfix"></div>' +
	        '<div class="modal-footer" style="text-align:center">' +
	        '</div>' +
	        '</div>' + '</div>' + '</div>');
	    kungeekui.ShowDialog = function(config) {
	        this.defaultConfig = {
	            title: '',
	            content: '',
	            buttons: [{
	                text: '取消',
	                event: function() {
	                    kungeekui.modalDom.modal('hide');
	                },
	                bgColor: 'bgcolorcancel'
	            }],
	            width: '90%',
	            hasDefaultBtn: true,
	            animated: 'fadeInDown'
	        };

	        this.cfg = $.extend(true, {}, this.defaultConfig, config);
	        if (this.cfg.hasDefaultBtn && config.buttons && config.buttons instanceof Array) {
	            this.cfg.buttons.unshift(this.defaultConfig.buttons[0]);
	        }

	        if (!config.buttons) {
	            this.cfg.buttons = []
	        }

	        this.$content = typeof this.cfg.content === 'string' ? $(this.cfg.content) : this.cfg.content;
	        this.isFirstAdd = true; // 是否第一次加载content
	        this.handle = {};

	        return this.init();
	    }
	    kungeekui.ShowDialog.prototype = {
	            init: function() {
	                var _this = this;
	                // boostrap 事件转移
	                kungeekui.modalDom.on('show.bs.modal', function(e) {
	                    _this.fire('show');
	                })
	                kungeekui.modalDom.on('shown.bs.modal', function(e) {
	                    _this.fire('shown');
	                })
	                kungeekui.modalDom.on('hide.bs.modal', function(e) {
	                    _this.fire('hide');
	                })
	                kungeekui.modalDom.on('hidden.bs.modal', function(e) {
	                    _this.fire('hidden');
	                })

	            },
	            show: function(config) {
	                config = typeof config == 'object' ? config : 'show';
	                this.clear();
	                this.setElement();
	                kungeekui.modalDom.modal(config);
	                this.fire('show');
	            },
	            hide: function() {
	                kungeekui.modalDom.modal('hide');
	            },
	            setElement: function() {
	                //头部设置
	                kungeekui.modalDom.find('.modal-header').removeClass('borderNone');
	                if (!this.cfg.title) {
	                    kungeekui.modalDom.find('.modal-header').addClass('borderNone');
	                    kungeekui.modalDom.find('.modal-title').html('&#12288;');
	                } else {
	                    kungeekui.modalDom.find('.modal-title').html(this.cfg.title);
	                }
	                //内容设置
	                if (this.isFirstAdd) {
	                    kungeekui.modalDom.find('.modal-body').append(this.$content.show().css('visibility', 'visible'));
	                    this.isFirstAdd = false
	                } else {
	                    this.$content.show().css('visibility', 'visible');
	                }
	                //底部设置
	                if (!this.cfg.buttons || this.cfg.buttons.length == 0) {
	                    kungeekui.modalDom.find('.modal-footer').hide();
	                } else {
	                    kungeekui.modalDom.find('.modal-footer').show();
	                    for (var i = 0; i < this.cfg.buttons.length; i++) {
	                        var button = $('<button type="button" class="btn btn-success btn-sm ' +
	                            this.cfg.buttons[i].bgColor +
	                            ' kungeek-btn">' +
	                            this.cfg.buttons[i].text + '</button>');
	                        button.on('click', this.cfg.buttons[i].event);
	                        kungeekui.modalDom.find('.modal-footer').append(button)
	                    }
	                }
	                //宽度设置
	                kungeekui.modalDom.find('.modal-dialog').css({
	                    'width': this.cfg.width,
	                    'margin': this.cfg.margin
	                });
	                //动画设置
	                kungeekui.modalDom.addClass(this.cfg.animated);
	            },
	            clear: function() {
	                kungeekui.modalDom.find('.modal-title').empty();
	                kungeekui.modalDom.find('.modal-footer').empty();
	                kungeekui.modalDom.find('.modal-body').children().hide();
	            },
	            on: function(event, fn) {
	                if (typeof event == 'string' && typeof fn == 'function') {
	                    if (!this.handle[event]) {
	                        this.handle[event] = [];
	                    }
	                    this.handle[event].push(fn)
	                }
	            },
	            fire: function(event, data) {
	                if (!this.handle[event]) {
	                    return;
	                }
	                for (var i = 0; i < this.handle[event].length; i++) {
	                    this.handle[event][i](data);
	                }
	            }
	        }
	        // -------------------------------Datagird 数据表格
	    kungeekui.Datagrid = function(option) {
	        if (!option.target || option.target.get(0).tagName != 'TABLE') {
	            throw new Error(
	                '实例化 Datagird 必须传入 target 参数，target为$(TABLE标签选择器字符串)');
	            return;
	        }
	        this.defaultOption = {
	            minTrNums: 10, //表格最小行数
	            // minItemNums: 10, //表格未加载数据前最小的行数
	            title: null, //表格标题
	            source: null, //表格数据源
	            paging: false, //表格分页
	            onlyCheckOne: false, //是否单选，默认复选
	            hasOrder: true, //是否有排序列
	            fixedOrderField: true, //是否左边固定排序列
	            hasCheckBox: false, //是否需要checkbox
	            fixedCheckBoxField: true, //是否左边固定checkbox列
	            fieldDrag: false, //是否允许列拖动
	            width: '100%', //表格宽度
	            height: 'auto', //表格高度
	            trAnimation: null, //tr动画
	            extraClass: 'table table-striped table-bordered table-hover', //表格额外css样式
	            fixedThead: true, //是否固定表头
	            defaultPage: 1, //默认加载第几页
	            fieldOrder: true, //是否需要列排序
	            minFieldWidth: 70, //最小的列宽
	        };
	        this.option = $.extend(true, {}, this.defaultOption, option);
	        return this.init();
	    }
	    kungeekui.Datagrid.prototype = {
	        init: function() {
	            var _this = this;
	            this.$table = this.option.target;
	            this.$table.wrap('<div class="kungeek-datagrid-wrap">');
	            this.$tableWrap = this.$table.parent('.kungeek-datagrid-wrap');
	            this.$tableWrap.wrap('<div class="kungeek-datagrid-container">');
	            this.$tableContainer = this.$tableWrap.parent('.kungeek-datagrid-container');;
	            this.$table.get(0).datagrid = this; //dom对象引用到实例化datagrid
	            this.readedTableData = []; //已经读取的数据
	            this.pagedResult = {}; //分页数据

	            this.fields = []; //table列名集合
	            this.leftfields = []; //左边固定列集合
	            this.rightfields = []; //右边固定列集合
	            this.extraFields = []; //额外增加的列集合
	            this.modifyFields = []; //修改的列
	            this.extraFieldsLength = 0; //初始增加列的个数
	            this.page = 1; //默认传递第1页
	            this.pageSize = 10; //默认一页10条数据
	            this.isRendering = false; //是否正在渲染中
	            this.hasLoaded = true; //是否加载完数据

	            this.isFirstCreateTr = true; //是否第一次创建行
	            this.handle = {}; //事件句柄
	            this.getAttrVal();
	            this.addExtraClass();
	            this.setTitle();
	            this.getThead();
	            this.initTable();
	            this.initTfoot();
	            this.listenResize();
	            if (this.option.paging) { //如果需要分页
	                this.initPaging();
	            }
	            if (this.option.fixedThead) { //如果有固定表头
	                this.listenScorll(); //监控滚动
	            }
	            this.getSourceData(this.option.defaultPage, function() {
	                _this.render(); //渲染表格
	            }); //从后台获取数据,默认传递第一页参数
	        },
	        getAttrVal: function() { // 获取table配置属性
	            try {
	                var attr_option = this.$table.attr('kg-data-option') ? this.$table.attr('kg-data-option').toObject() : {};
	            } catch (e) {
	                throw new Error('kg-data-option格式不正确');
	            }
	            var _this = this;
	            this.option = $.extend(true, {}, this.option, attr_option);
	            $.each(this.option, function(item, val) {
	                _this.option[item] = _this.$table.attr('kg-data-' + item) ? _this.$table.attr('kg-data-' + item) : _this.option[item];
	                if (_this.option[item] == "true") {
	                    _this.option[item] = true
	                } else if (_this.option[item] == "false") {
	                    _this.option[item] = false
	                }
	                _this.$table.removeAttr('kg-data-' + item);
	            })

	            this.$table.removeAttr('kg-data-option');

	            this.trNum = this.option.minTrNums - 0; //设置初始行数

	            //设置checkbox 和 order固定列
	            if (this.option.hasCheckBox && this.option.fixedCheckBoxField) {
	                this.leftfields.push({ title: 'checkbox', option: { 'field': 'checkbox', 'width': 50 } })
	            } else if (this.option.hasCheckBox) {
	                this.fields.push({ title: 'checkbox', option: { 'field': 'checkbox', 'width': 50 } })
	            }

	            if (this.option.hasOrder && this.option.fixedOrderField) {
	                this.leftfields.push({ title: 'order', option: { 'field': 'order', 'width': 50 } })
	            } else if (this.option.hasOrder) {
	                this.fields.push({ title: 'order', option: { 'field': 'order', 'width': 50 } })
	            }
	        },
	        addExtraClass: function() { // 添加新类名到table，如果有的话
	            this.$table.addClass(this.option.extraClass);
	        },
	        setTitle: function() { // 设置table的title，如果有的话
	            if (this.option.title) {
	                this.$table.before('<p>' + this.option.title + '</p>')
	            }
	        },
	        getThead: function() { // 获取thead属性数据,配置field
	            var _this = this;
	            this.$thead = this.$table.find('thead'); // thead
	            var thDefaultOption = { //th的默认配置
	                width: 'initial', //列宽度，如果没有配置则自适应，最小宽度为minFieldWidth
	                field: '', //列名
	                align: 'left', //对齐方式
	                newline: false, //本列td内容是否换行，不换行超出部分省略号表示
	                fixed: false, //是否固定列，true|'left'为左边固定，'right'为右边固定
	                orderName: '', //排序的名字，如果有值代表这个列可以排序，并且每次请求会将此名传到后台
	                rule: null //本列输出的值采用的变换规则：输出的值 -> 输出的值[rule]() 的值
	            };
	            this.$thead.find('th').each(function(i) {
	                var $th = $(this);
	                //获取th配置属性
	                var field = {
	                    index: i,
	                    option: $(this).attr('kg-data-option') ? $(this).attr('kg-data-option').toObject() : {},
	                    title: $(this).html()
	                }
	                field.option = $.extend(true, {}, thDefaultOption, field.option);
	                $.each(field.option, function(item, val) {
	                    field.option[item] = $th.attr('kg-data-' + item) ? $th.attr('kg-data-' + item) : field.option[item];
	                });
	                $th.remove();
	                if (field.option.fixed) {
	                    if (field.option.fixed == 'left') {
	                        _this.leftfields.push(field);
	                    } else if (field.option.fixed == 'right') {
	                        _this.rightfields.push(field);
	                    } else {
	                        _this.leftfields.push(field);
	                    }
	                } else {
	                    _this.fields.push(field);
	                }
	            })
	        },
	        initTable: function() {
	            //table wrap
	            if (this.option.width) {
	                this.$tableContainer.css({
	                    'width': this.option.width
	                })
	            }
	            if (this.option.height) {
	                this.$tableContainer.css({
	                    'height': this.option.height
	                })
	            }
	            //左边table
	            if (this.leftfields.length > 0) {
	                this.creatTable('left');
	                this.initThead('left');
	                this.createTbodyTr('left');
	            }
	            //左边table
	            if (this.rightfields.length > 0) {
	                this.creatTable('right');
	                this.initThead('right');
	                this.createTbodyTr('right');
	            }

	            this.initThead();
	            this.updateTableWidth();
	            this.initTbody();
	            this.createTbodyTr();
	            this.trEvent();
	        },
	        creatTable: function(dir) {
	            var table = $('<table>').addClass(this.$table.attr('class'));
	            var tableWrap = $('<div class="kungeek-datagrid-wrap">').addClass(dir + '-table-fiexd');
	            var thead = $('<thead><tr></tr></thead>');
	            var tbody = $('<tbody>');

	            tableWrap.append(table.append(thead).append(tbody));
	            this['$' + dir + 'table'] = table;
	            this['$' + dir + 'tableWrap'] = tableWrap;
	            if (dir == 'left') {
	                this.$tableWrap.before(tableWrap);
	            } else {
	                this.$tableWrap.after(tableWrap);
	            }

	        },
	        initThead: function(dir) { //初始化thead
	            var _this = this;
	            var dir = arguments[0] ? arguments[0] : '';
	            var table = this['$' + dir + 'table'];
	            var thead = table.find('thead');
	            var tbody = table.find('tbody');
	            var fields = this[dir + 'fields'];
	            thead.find('th').remove();
	            fields.map(function(field, i) {
	                if (field.title == 'order') { //如果需要显示序号
	                    var th = $('<th>').addClass('kg-datagird-orderField').css('width', field.option.width);
	                    var twrap = $('<div class="kg-datagird-twrap">').html('序号');
	                    th.append(twrap);
	                    thead.find('tr').append(th);
	                    return;
	                }
	                if (field.title == 'checkbox') { //如果需要显示checkbox	
	                    var th = $('<th>').addClass('kg-datagird-checkField').css('width', field.option.width);
	                    var twrap = $('<div class="kg-datagird-twrap">').append('<div class="kg-checkbox"><input type="checkbox" id="kg-c-0"><label for="kg-c-0"></label></div>');
	                    th.append(twrap);
	                    //设置全选
	                    th.find('input[type=checkbox]#kg-c-0').on('click', function() {
	                        if ($(this).is(':checked')) {
	                            tbody.find('tr .kungeekui-datagird-checkbox input[type=checkbox]').each(function() {
	                                $(this).prop('checked', true);
	                            })

	                        } else {
	                            tbody.find('tr .kungeekui-datagird-checkbox input[type=checkbox]').each(function() {
	                                $(this).prop('checked', false);
	                            })
	                        }
	                    })
	                    thead.find('tr').append(th);
	                    if (_this.option.onlyCheckOne) { //如果只能单选
	                        th.empty();
	                    }
	                    return;
	                }
	                var th = $('<th>');
	                var twrap = $('<div class="kg-datagird-twrap">').html(field.title);
	                th.append(twrap);
	                thead.find('tr').append(th);
	                if (_this.option.fieldOrder) { //如果需要列排序,添加排序图标
	                    if (field.option.orderName) {
	                        th.addClass('order');
	                    }
	                }
	            })


	            //更新宽度 
	            thead.find('th').each(function(i) {
	                // var twrap = $('<div class="kg-datagird-twrap">').append($(this).children()).append($(this).html());
	                // $(this).empty().append(twrap);
	                if (fields[i].option.width && fields[i].option.width != 'initial') {
	                    $(this).css('width', fields[i].option.width)
	                } else {
	                    if (dir) {
	                        $(this).css('width', 120)
	                    }

	                }
	            })
	        },
	        updateTableWidth: function() {
	            var leftWidth = 0,
	                rightWidth = 0,
	                allWidth = this.$tableContainer.innerWidth(),
	                width = 0;
	            //左边table
	            if (this.leftfields.length > 0) {
	                this.leftfields.map(function(field) {
	                    width = (field.option.width != "initial") ? parseFloat(field.option.width) : 120;
	                    leftWidth += width;
	                })
	                width = (((leftWidth + 1) / allWidth) * 100);
	                this.$lefttableWrap.css('width', width + '%');
	            }
	            //右边table
	            if (this.rightfields.length > 0) {
	                this.rightfields.map(function(field) {
	                    width = 0;
	                    width = (field.option.width != "initial") ? parseFloat(field.option.width) : 120;
	                    rightWidth += width;
	                })
	                width = (((rightWidth + 1) / allWidth) * 100);
	                this.$righttableWrap.css('width', width + '%');
	            }
	            this.$tableWrap.css('width', (allWidth - (leftWidth + rightWidth + 2)) * 100 / allWidth + '%')

	        },
	        listenResize: function() {
	            var _this = this;
	            $(window).on('resize', function() {
	                _this.updateTableWidth();
	                _this.updateTrHeight();
	                //更新最小列宽
	                _this.$tableContainer.find('th:not(.kg-datagird-orderField,.kg-datagird-checkField)').each(function() {
	                    if (this.offsetWidth < _this.option.minFieldWidth) {
	                        $(this).css('width', _this.option.minFieldWidth)
	                    }
	                })

	                //设置阴影
	                if (_this.rightfields.length) {
	                    if (_this.$table.width() > _this.$tableWrap.width()) {
	                        _this.$tableContainer.find('.right-table-fiexd').addClass('showShadow');
	                    } else {
	                        _this.$tableContainer.find('.right-table-fiexd').removeClass('showShadow');
	                    }
	                }
	            })
	        },
	        initTbody: function() { //初始化tbody
	            this.$tbody = $('<tbody></tbody>');
	            this.$thead.after(this.$tbody);
	        },
	        initTfoot: function() { //初始化tbody
	            // if (this.option.paging) { //如果需要分页
	            //     this.$tfoot = $('<tfoot><tr><td></td></tr></tfoot>');
	            //     this.$tbody.after(this.$tfoot);
	            //     this.initPaging();
	            // }
	        },
	        initPaging: function() {
	            if (!this.option.source) {
	                throw new Error('必须指定数据源才能创建分页（paging属性依赖于source属性）');
	            }
	            this.$pagingWrap = $('<div class="kungeek-datagrid-paging-wrap">');
	            this.$tableContainer.append(this.$pagingWrap);
	            var pagedResult = {
	                total: 0,
	                info: {
	                    first: 1,
	                    last: 0,
	                    next: 1,
	                    pageIndex: 1,
	                    pageSize: 10,
	                    prev: 1,
	                    totalPage: 0
	                }
	            };
	            this.pagedResult = pagedResult;
	            this.renderPaging();
	        },
	        renderPaging: function() {
	            this.$paging = $('<div class="kungeekui-datagrid-paging form-inline">');
	            this.$paging.append('<a href="javascript:void(0)" class="btn btn-default kungeekui-datagrid-paging-fp">首页</a>');
	            this.$paging.append('<a href="javascript:void(0)" class="btn btn-default kungeekui-datagrid-paging-prev">上一页</a>');
	            this.$paging.append('<a href="javascript:void(0)" class="btn btn-default kungeekui-datagrid-paging-pageIndex" data-index="1">1</a>');
	            this.$paging.append('<a href="javascript:void(0)" class="btn btn-default kungeekui-datagrid-paging-pageIndex" data-index="2">2</a>');
	            this.$paging.append('<a href="javascript:void(0)" class="btn btn-default kungeekui-datagrid-paging-pageIndex" data-index="3">3</a>');
	            this.$paging.append('<a href="javascript:void(0)" class="btn btn-default kungeekui-datagrid-paging-pageIndex" data-index="4">4</a>');
	            this.$paging.append('<a href="javascript:void(0)" class="btn btn-default kungeekui-datagrid-paging-pageIndex" data-index="5">5</a>');
	            this.$paging.append('<a href="javascript:void(0)" class="btn btn-default kungeekui-datagrid-paging-next">下一页</a>');
	            this.$paging.append('<a href="javascript:void(0)" class="btn btn-default kungeekui-datagrid-paging-ep">尾页</a>');
	            this.$paging.append('<label>共 <span class="kungeekui-datagrid-paging-ptotal"></span> 页，</label>');
	            this.$paging.append('<label>当前第 <span class="kungeekui-datagrid-paging-np"></span> 页，跳转到第 </label>');
	            this.$paging.append('<input type="number" class="form-control kungeekui-datagrid-paging-gtp" min="1">');
	            this.$paging.append('<label> 页</label>');
	            this.$paging.append('<a href="javascript:void(0)" class="btn btn-default kungeekui-datagrid-paging-gtpBtn">确定</a>');
	            this.$paging.append('<select class="form-control kungeekui-datagrid-paging-psize"><option>10</option><option>20</option><option>50</option><option>100</option><option>200</option></select>');
	            this.$paging.append('<label>条/页</label>');
	            this.$paging.append('<label>共<span class="kungeekui-datagrid-paging-atotal"></span>条</label>');
	            this.$paging.append('<a href="javascript:void(0)" class="btn btn-default kungeekui-datagrid-paging-refresh">刷新</a>');
	            this.$pagingWrap.append(this.$paging);
	            var _this = this;
	            //注册事件
	            this.$paging.find('.kungeekui-datagrid-paging-fp').on('click', function() { //跳转到第1页
	                _this.gotoPage(1);
	            })
	            this.$paging.find('.kungeekui-datagrid-paging-ep').on('click', function() { //跳转到最后一页
	                _this.gotoPage(_this.pagedResult.info.totalPage);
	            })
	            this.$paging.find('.kungeekui-datagrid-paging-prev').on('click', function() { //跳转到上一页
	                if (_this.page <= 1) {
	                    _this.gotoPage(1);
	                    return;
	                }
	                _this.gotoPage(_this.page - 0 - 1);
	            })
	            this.$paging.find('.kungeekui-datagrid-paging-next').on('click', function() { //跳转到下一页
	                if (_this.page >= _this.pagedResult.info.totalPage) {
	                    _this.gotoPage(_this.pagedResult.info.totalPage);
	                    return;
	                }
	                _this.gotoPage(_this.page - 0 + 1);
	            })
	            this.$paging.find('.kungeekui-datagrid-paging-gtpBtn').on('click', function() { //跳转到第n页
	                var page = parseInt(_this.$paging.find('.kungeekui-datagrid-paging-gtp').val());
	                if (!page || page < 1) {
	                    _this.$paging.find('.kungeekui-datagrid-paging-gtp').val('');
	                    return;
	                }
	                if (page > _this.pagedResult.info.totalPage) {
	                    _this.gotoPage(_this.pagedResult.info.totalPage);
	                    return;
	                }
	                _this.gotoPage(page);
	            })
	            this.$paging.find('.kungeekui-datagrid-paging-psize').on('change', function() { //选择每页展示条数
	                var pageSize = $(this).find("option:selected").text();
	                _this.pageSize = pageSize;
	                _this.gotoPage(_this.page);
	            })

	            this.$paging.find('.kungeekui-datagrid-paging-pageIndex').on('click', function() { //跳转到某页
	                var page = $(this).html() - 0;
	                _this.gotoPage(page);
	            })

	            this.$tableContainer.on('click', '.kungeekui-datagrid-paging-refresh', function() { //跳转到某页
	                _this.refresh();
	            })
	        },
	        setPaging: function() {
	            var _this = this;
	            var tableData = [];
	            this.readedTableData.map(function(item) {
	                if (item.page == _this.page) {
	                    tableData = item.tableData;
	                    return;
	                }
	            })
	            this.$tableContainer.find('.kg-paging-info').remove();
	            this.$paging.show();
	            if (tableData.length == 0) {
	                this.$tableContainer.append('<div class="kg-paging-info"><p><i class="fa fa-exclamation-triangle fa-lg" aria-hidden="true" style=" color: #ff5f5f;"></i> 暂无数据，可以尝试 <a href="javascript:void(0)" class="btn btn-default btn-sm kungeekui-datagrid-paging-refresh">刷新</a></p></div>');
	                this.$paging.hide();
	                return;
	            }
	            this.$paging.find('.kungeekui-datagrid-paging-ptotal').html(this.pagedResult.info.totalPage);
	            this.$paging.find('.kungeekui-datagrid-paging-atotal').html(this.pagedResult.total);
	            this.$paging.find('.kungeekui-datagrid-paging-psize').val(this.pagedResult.info.pageSize);
	            this.$paging.find('.kungeekui-datagrid-paging-np').html(this.pagedResult.info.pageIndex);
	            this.$paging.find('.kungeekui-datagrid-paging-gtp').val('');
	            var pages = [];
	            this.page = this.page - 0;
	            if (this.pagedResult.info.totalPage > 5) {
	                if (this.page < 3) {
	                    pages = [1, 2, 3, 4, 5]
	                } else if (this.page == this.pagedResult.info.totalPage) {
	                    pages = [this.page - 4, this.page - 3, this.page - 2, this.page - 1, this.page]
	                } else if (this.page == this.pagedResult.info.totalPage - 1) {
	                    pages = [this.page - 3, this.page - 2, this.page - 1, this.page, this.page + 1]
	                } else {
	                    pages = [this.page - 2, this.page - 1, this.page, this.page + 1, this.page + 2]
	                }
	            } else if (this.pagedResult.info.totalPage <= 5) {
	                for (var i = 0; i < this.pagedResult.info.totalPage; i++) {
	                    pages.push(i + 1);
	                }
	            }
	            this.$paging.find('.kungeekui-datagrid-paging-pageIndex').each(function(i) {
	                $(this).show();
	                if (pages[i]) {
	                    $(this).html(pages[i]);
	                } else {
	                    $(this).hide();
	                }

	                $(this).removeClass('btn-info');
	                if ($(this).html() == _this.page) {
	                    $(this).addClass('btn-info');
	                }
	            })
	        },
	        updateTrNum: function() { //更新行数
	            var dataLength = this.dataLength;
	            //判断行数
	            if (!this.imposedTrNum) { //如果强制了行数
	                if (this.option.paging) { //如果需要分页
	                    if (dataLength == this.trNum) {
	                        return false; //如果行数足够则不再创建
	                    }
	                    if (dataLength < this.trNum) {
	                        if (dataLength >= this.option.minTrNums) {
	                            this.trNum = dataLength
	                        } else {
	                            this.trNum = this.option.minTrNums
	                        }
	                    } else if (dataLength > this.trNum) {
	                        this.trNum = dataLength;
	                    }
	                } else {
	                    if (this.trNum > dataLength) {
	                        return false; //如果行数足够则不再创建
	                    }
	                    if (this.trNum < dataLength) { //如果第一次获取的数据数目大于默认行数，则刷新创建行数
	                        this.trNum = dataLength;
	                    }
	                }
	            }
	        },
	        createTbodyTr: function(dir) { //创建空数据行
	            var _this = this;
	            var dir = arguments[0] ? arguments[0] : '';
	            var table = this['$' + dir + 'table'];
	            var thead = table.find('thead');
	            var tbody = table.find('tbody');
	            var fields = this[dir + 'fields'];


	            this.imposedTrNum = false;
	            this.trChange = true;
	            //如果有变化则重新创建行
	            tbody.empty();
	            for (var i = 0; i < this.trNum; i++) { //原本的行
	                var tr = $('<tr>');
	                if (this.option.trAnimation) {
	                    var tr = $('<tr class="animated ' + this.option.trAnimation + '">');
	                    tr.css({
	                        'animation-delay': i / 10 + 's',
	                        '-webkit-animation-delay': i / 10 + 's',
	                    })
	                }
	                fields.map(function(val, i) {
	                    var field = val;
	                    if (field.title == 'checkbox') {
	                        var td = $('<td class="kungeekui-datagird-checkbox">');
	                        tr.append(td);
	                        return;
	                    }
	                    if (field.title == 'order') {
	                        var td = $('<td class="kungeekui-datagird-order">');
	                        tr.append(td);
	                        return;
	                    }
	                    var td = $('<td>').css({
	                        'text-align': field.option.align ? field.option.align : 'center'
	                    });
	                    tr.append(td);
	                })
	                tbody.append(tr);
	            }
	        },
	        createExtraTr: function() {
	            var _this = this;
	            if (!this.trChange) {
	                if (this.extraFieldsLength == this.extraFields.length) {
	                    return;
	                }
	            }
	            //外增加的列头
	            if (this.extraFieldsLength != this.extraFields.length) {
	                _this.$thead.find('tr').find('th').each(function() {
	                    if (this.isExtraField) {
	                        $(this).remove();
	                    }
	                });
	                for (var i = 0; i < _this.extraFields.length; i++) {
	                    var th = $('<th>').css('width', _this.extraFields[i].width ? _this.extraFields[i].width : 120);
	                    var twrap = $('<div>').addClass('kg-datagird-twrap').html(_this.extraFields[i].title).css('width', _this.extraFields[i].width ? _this.extraFields[i].width : '100%');
	                    th.append(twrap);
	                    th.get(0).isExtraField = true;
	                    if (_this.extraFields[i].index) { //如果有指定插入位置
	                        _this.$thead.find('tr').find('th').eq(_this.extraFields[i].index).before(th);
	                    } else {
	                        _this.$thead.find('tr').append(th);
	                    }
	                }
	                this.extraFieldsLength = this.extraFields.length;
	            }
	            //外增加的列表
	            _this.$tbody.find('tr').each(function() {
	                $(this).find('td').each(function() {
	                    if (this.isExtraField) {
	                        $(this).remove();
	                    }
	                })
	                for (var i = 0; i < _this.extraFields.length; i++) {
	                    var td = $('<td>');
	                    td.addClass('kungeekui-datagird-extraField').get(0).isExtraField = true;
	                    if (_this.extraFields[i].index) { //如果有指定插入位置
	                        $(this).find('td').eq(_this.extraFields[i].index).before(td);
	                    } else {
	                        $(this).append(td);
	                    }
	                }
	            });
	            //排序
	            _this.extraFields.sort(function(a, b) {
	                var value1 = a.index,
	                    value2 = b.index;
	                if (value1 < value2) {
	                    return 1;
	                } else if (value1 > value2) {
	                    return -1;
	                } else {
	                    return 0;
	                }
	            });
	            this.trChange = false;
	        },
	        trEvent: function() { //注册tr事件
	            var _this = this;
	            //阻止行内操作元素 事件冒泡
	            this.$tableContainer.find('tbody').off('click.bubble');
	            this.$tableContainer.find('tbody').on('click.bubble', 'input:not(input[type="checkbox"]),button,a,select', function(e) {
	                e.stopPropagation();
	            })
	            this.$tableContainer.find('tbody').off('click.select');
	            this.$tableContainer.find('tbody').on('click.select', 'tr', function(e) {
	                var index = e.currentTarget.rowIndex;
	                var checkbox = _this.$tableContainer.find('tbody').find('.kungeekui-datagird-checkbox input[id="kg-c-' + index + '"]');
	                var isCheck = checkbox.prop("checked");
	                if (_this.option.onlyCheckOne) { //如果只能单选
	                    _this.$tableContainer.find('tbody').find('tr .kungeekui-datagird-checkbox input[type=checkbox]').prop('checked', false);
	                }
	                if (!isCheck) {
	                    checkbox.prop("checked", true)
	                } else {
	                    checkbox.prop("checked", false)
	                }
	            })
	            this.$tableContainer.find('tbody').off('mouseover.hover');
	            this.$tableContainer.find('tbody').on('mouseover.hover', 'tr', function(e) {
	                var index = e.currentTarget.rowIndex - 1;
	                _this.$tableContainer.find('tbody').each(function() {
	                    $(this).find('tr').eq(index).addClass('hover');
	                })
	            })
	            this.$tableContainer.find('tbody').off('mouseleave.hover');
	            this.$tableContainer.find('tbody').on('mouseleave.hover', 'tr', function(e) {
	                var index = e.currentTarget.rowIndex - 1;
	                _this.$tableContainer.find('tbody').each(function() {
	                    $(this).find('tr').eq(index).removeClass('hover');
	                })
	            })
	        },
	        clearTbodyTr: function() {
	            this.$tableContainer.find('tbody').find('tr').each(function() {
	                this.trData = {};
	                $(this).find('td').empty();
	            })
	        },
	        getSourceData: function(page, callback) { // 读取数据,传递页码参数和回调函数
	            if (!this.option.source) { //如果没有指定数据源，则不执行
	                return;
	            }
	            var _this = this;
	            this.hasLoaded = false; //是否加载完数据
	            var tableData = [];
	            this.setLoader(true); //加载提示开始

	            //排序规则
	            if (this.orderRule) {
	                var isAsc = null;
	                if (_this.orderRule.rule) {
	                    isAsc = this.orderRule.orderName + ' ' + this.orderRule.orderDes[this.orderRule.rule]
	                }
	            }
	            // 开始异步加载数据
	            $.ajax({
	                    url: this.option.source,
	                    type: 'GET',
	                    data: { pageNum: page, pageSize: _this.pageSize, isAsc: isAsc },
	                    success: function(res) {
	                        if (!res.pagedResult) {
	                            _this.setLoader(false); //加载提示结束
	                            _this.setPaging();
	                            return false;
	                        }
	                        if (res.pagedResult.hasOwnProperty('data')) {
	                            res.data = res.pagedResult.data;
	                        }
	                        if (res.statusCode == 0 || res.data == 'undefined' || res.data == null) {
	                            _this.setLoader(false); //加载提示结束
	                            _this.setPaging();
	                            return false;
	                        }
	                        //	                        if (res.data.length == 0 && _this.page != 1) {
	                        //	                            _this.gotoPage(1);
	                        //	                            return false;
	                        //	                        }
	                        _this.pagedResult = res.pagedResult;
	                        tableData = res.data;
	                        var oneReadedTableData = {
	                            page: page,
	                            tableData: tableData
	                        };
	                        var isSamePage = false;
	                        for (var i = 0; i < _this.readedTableData.length; i++) {
	                            if (_this.readedTableData[i].page == page) {
	                                _this.readedTableData[i] = oneReadedTableData; //覆盖数据到存储
	                                isSamePage = true;
	                                break;
	                            }
	                        }
	                        if (!isSamePage) { _this.readedTableData.push(oneReadedTableData); } //添加数据到存储
	                        _this.page = page;
	                        _this.pageSize = res.pagedResult.info.pageSize;
	                        _this.hasLoaded = true;
	                        callback(); //回调执行render
	                        _this.setLoader(false); //加载提示结束
	                    },
	                    error: function(err) {
	                        _this.setLoader(false); //加载提示结束
	                        _this.setPaging();
	                        return false;
	                    }
	                })
	                //	            setTimeout(function() {
	                //	                var res = {
	                //	                    data: [{ _id: '2345YTHGFBVD546YT', address: '许昌县陈曹乡陈曹街', lxr: '党继伟', mphone: '1', lastVisitRecord: '拒接' },
	                //	                        { _id: '2345YTWQ3Q2F546YT', address: '许昌市瑞祥路龙湖时代公寓308号', lxr: '刘三伟', mphone: '2', lastVisitRecord: '拒接' },
	                //	                        { _id: '2SFFBVD546YSDSD23', address: '许昌市工农路与阳光大道交叉口', lxr: '万兴龙', mphone: '3', lastVisitRecord: '拒接' },
	                //	                        { _id: '2DZSZAR5GzFSD3DYT', address: '许昌市颂苑第12幢06、07号门面房', lxr: '王国尚', mphone: '4', lastVisitRecord: '拒接' },
	                //	                        { _id: '2345YTHGFBSDF3FSA', address: '许昌市东城区大龙魏村', lxr: '张东亮', mphone: '5', lastVisitRecord: '问凭什么让他投资，我说是合作，他挂' },
	                //	                        { _id: '2345YTHGFBSDF3FSA', address: '许昌市东城区大龙魏村', lxr: '张东亮', mphone: '6', lastVisitRecord: '问凭什么让他投资，我说是合作，他挂' },
	                //	                        { _id: '2345YTHGFBSDF3FSA', address: '许昌市东城区大龙魏村', lxr: '张东亮', mphone: '7', lastVisitRecord: '问凭什么让他投资，我说是合作，他挂' },
	                //	                        { _id: '2345YTHGFBSDF3FSA', address: '许昌市东城区大龙魏村', lxr: '张东亮', mphone: '8', lastVisitRecord: '问凭什么让他投资，我说是合作，他挂' },
	                //	                        { _id: '2345YTHGFBSDF3FSA', address: '许昌市东城区大龙魏村', lxr: '张东亮', mphone: '8', lastVisitRecord: '问凭什么让他投资，我说是合作，他挂' },
	                //	                        { _id: '2345YTHGFBSDF3FSA', address: '许昌市东城区大龙魏村', lxr: '张东亮', mphone: '8', lastVisitRecord: '问凭什么让他投资，我说是合作，他挂' },
	                //	                        { _id: '2345YTHGFBSDF3FSA', address: '许昌市东城区大龙魏村', lxr: '张东亮', mphone: '8', lastVisitRecord: '问凭什么让他投资，我说是合作，他挂' },
	                //	                        { _id: '2345YTHGFBSDF3FSA', address: '许昌市东城区大龙魏村', lxr: '张东亮', mphone: '8', lastVisitRecord: '问凭什么让他投资，我说是合作，他挂' },
	                //	                        { _id: '2345YTHGFBSDF3FSA', address: '许昌市东城区大龙魏村', lxr: '张东亮', mphone: '8', lastVisitRecord: '问凭什么让他投资，我说是合作，他挂' },
	                //	                        { _id: '2345YTHGFBSDF3FSA', address: '许昌市东城区大龙魏村', lxr: '张东亮', mphone: '8', lastVisitRecord: '问凭什么让他投资，我说是合作，他挂' },
	                //	                        { _id: '2345YTHGFBSDF3FSA', address: '许昌市东城区大龙魏村', lxr: '张东亮', mphone: '8', lastVisitRecord: '问凭什么让他投资，我说是合作，他挂' },
	                //	                        { _id: '2345YTHGFBSDF3FSA', address: '许昌市东城区大龙魏村', lxr: '张东亮', mphone: '8', lastVisitRecord: '问凭什么让他投资，我说是合作，他挂' },
	                //	                    ],
	                //	                    pagedResult: {
	                //	                        total: 312,
	                //	                        info: {
	                //	                            first: 1,
	                //	                            last: 6,
	                //	                            next: 3,
	                //	                            pageIndex: 2,
	                //	                            pageSize: 20,
	                //	                            prev: 1,
	                //	                            totalPage: 16
	                //	                        }
	                //	                    }
	                //	                };
	                //	                _this.pagedResult = res.pagedResult;
	                //	                tableData = res.data;
	                //	                var oneReadedTableData = {
	                //	                    page: page,
	                //	                    tableData: tableData
	                //	                };
	                //	                var isSamePage = false;
	                //	                for (var i = 0; i < _this.readedTableData.length; i++) {
	                //	                    if (_this.readedTableData[i].page == page) {
	                //	                        _this.readedTableData[i] = oneReadedTableData; //覆盖数据到存储
	                //	                        isSamePage = true;
	                //	                        break;
	                //	                    }
	                //	                }
	                //	                if (!isSamePage) { _this.readedTableData.push(oneReadedTableData); } //添加数据到存储
	                //	                _this.page = page;
	                //	                _this.pageSize = res.pagedResult.info.pageSize;
	                //	                _this.hasLoaded = true;
	                //	                callback(); //回调执行render
	                //	                _this.setLoader(false); //加载提示结束
	                //	            }, 200)
	        },
	        beforeRender: function() { //渲染之前的设置
	            this.fire('startRender', this.readedTableData); //开始渲染
	            this.$tableContainer.removeClass('rendered');
	            this.$tableContainer.addClass('rendering');
	        },
	        afterRender: function() { //渲染之后的设置
	            var _this = this;
	            this.$tableContainer.removeClass('rendering');
	            this.$tableContainer.addClass('rendered');
	            //更新最小列宽
	            this.$tableContainer.find('th:not(.kg-datagird-orderField,.kg-datagird-checkField)').each(function() {
	                if (this.offsetWidth < _this.option.minFieldWidth) {
	                    $(this).css('width', _this.option.minFieldWidth)
	                }
	            })

	            //清除所有checkbox 选中
	            if (this.option.hasCheckBox) {
	                $('input[type="checkbox"]#kg-c-0').prop('checked', false);
	            }

	            //更新固定列与原表格的行高
	            if (this.leftfields.length > 0 || this.rightfields.length > 0) {
	                this.updateTrHeight();
	                if (this.rightfields.length) {
	                    if (this.$table.width() > this.$tableWrap.width()) {
	                        _this.$tableContainer.find('.right-table-fiexd').addClass('showShadow');
	                    }
	                }
	            }

	            if (this.option.paging && !$.isEmptyObject(this.pagedResult)) { //如果需要分页则设置分页数据
	                this.setPaging();
	            }

	            //如果需要固定表头
	            if (this.option.fixedThead) {
	                //左边table
	                if (this.leftfields.length > 0) {
	                    this.createCopyThead('left');
	                }
	                //右边table
	                if (this.rightfields.length > 0) {
	                    this.createCopyThead('right');
	                }
	                this.createCopyThead();
	            }

	            //如果需要拖动列
	            if (this.option.fieldDrag) {
	                this.addFieldDragBtn();
	            }

	            //如果需要列排序
	            if (this.option.fieldOrder) {
	                this.addFieldOrderBtn();
	            }

	            this.fire('rendered', this.readedTableData); //渲染完成
	        },
	        render: function() { //渲染tbody,将数据放进tr
	            var _this = this;
	            if (!this.hasLoaded) {
	                return;
	            }
	            this.beforeRender(); //执行渲染前设置
	            // 将数据放进table
	            var tableData = [];
	            for (var i = 0; i < this.readedTableData.length; i++) { //获取当前页的数据
	                if (this.readedTableData[i].page == this.page) {
	                    tableData = this.readedTableData[i].tableData.slice(0);
	                }
	            }
	            //如果有排序 - 旧的前端排序
	            /*if (this.orderRule && this.orderRule.rule != 0) {
	                tableData.sort(function(a, b) {
	                    var value1 = a[_this.orderRule.fieldName],
	                        value2 = b[_this.orderRule.fieldName];
	                    if (value1 < value2) {
	                        return _this.orderRule.rule == 2 ? 1 : -1;
	                    } else if (value1 > value2) {
	                        return _this.orderRule.rule == 1 ? 1 : -1;
	                    } else {
	                        return 0;
	                    }
	                });
	            }*/
	            this.dataLength = tableData.length;
	            this.tableData = tableData;
	            //空白行的更新
	            this.updateTrNum(); //更新行数
	            this.createTbodyTr();
	            //左边table
	            if (this.leftfields.length > 0) {
	                this.createTbodyTr('left');
	            }
	            //右边table
	            if (this.rightfields.length > 0) {
	                this.createTbodyTr('right');
	            }
	            //额外添加的列
	            // if (this.extraFields.length > 0) { //如果有添加的列
	            //     this.createExtraTr();
	            // }
	            //清空行数据
	            this.clearTbodyTr(this.trNum);

	            //在已有的行中填充数据
	            this.insertData();
	            //左边table
	            if (this.leftfields.length > 0) {
	                this.insertData('left');
	            }
	            //右边table
	            if (this.rightfields.length > 0) {
	                this.insertData('right');
	            }

	            this.afterRender(); //执行渲染后设置
	        },
	        insertData: function(dir) { //将数据放进table中
	            var _this = this;
	            var dir = arguments[0] ? arguments[0] : '';
	            var table = this['$' + dir + 'table'];
	            var tbody = table.find('tbody');
	            var fields = this[dir + 'fields'];
	            var tableData = this.tableData;
	            for (var j = 0; j < this.trNum; j++) {
	                var tr = tbody.find('tr').eq(j);
	                if (!tableData[j]) { //第j行不存在数据，则代表填充完成，可以跳出循环
	                    break;
	                }
	                tr.get(0).trData = tableData[j]; //为tr设置data
	                tr.get(0).trData.trIndex = ((this.page - 1) * this.pageSize + (j + 1));
	                fields.map(function(field, i) {
	                    var td = tr.find('td').eq(i);
	                    if (field.title == 'checkbox' || field.title == 'order') {
	                        if (field.title == 'checkbox') {
	                            td.append('<div class="kg-datagird-twrap"><div class="kg-checkbox"><input type="checkbox" id="kg-c-' + (j + 1) + '"><label for="kg-c-' + (j + 1) + '"></label></div></div>');
	                        }
	                        if (field.title == 'order') {
	                            if (_this.option.paging) { //如果需要分页
	                                td.append('<div class="kg-datagird-twrap">' + ((_this.page - 1) * _this.pageSize + (j + 1)) + '</div>');
	                            } else {
	                                td.append('<div class="kg-datagird-twrap">' + (j + 1) + '</div>');
	                            }
	                        }
	                    } else {
	                        if (tableData[j][field.option.field]) {
	                            if (field.option.rule) {
	                                td.html('<div class="kg-datagird-twrap ' + (field.option.newline ? 'kg-datagird-twrap-newline' : '') + '" title="' + tableData[j][field.option.field].toString()[field.option.rule]() + '">' + tableData[j][field.option.field].toString()[field.option.rule]() + '</div>');
	                            } else {
	                                td.html('<div class="kg-datagird-twrap ' + (field.option.newline ? 'kg-datagird-twrap-newline' : '') + '" title="' + tableData[j][field.option.field] + '">' + tableData[j][field.option.field] + '</div>');
	                            }
	                        } else if (field.ruleFn) { //如果是添加的列
	                            if (field.option.rule) {
	                                td.html('<div class="kg-datagird-twrap ' + (field.option.newline ? 'kg-datagird-twrap-newline' : '') + '" title="' + field.ruleFn(tableData[j])[rule]() + '">' + field.ruleFn(tableData[j])[rule]() + '</div>');
	                            } else {
	                                td.html('<div class="kg-datagird-twrap ' + (field.option.newline ? 'kg-datagird-twrap-newline' : '') + '" >' + field.ruleFn(tableData[j]) + '</div>');
	                            }
	                        } else {
	                            td.html('<div class="kg-datagird-twrap ' + (field.option.newline ? 'kg-datagird-twrap-newline' : '') + '" ></div>');
	                        }
	                    }
	                    if (_this.modifyFields.length > 0) { //如果有修改的列
	                        for (var x = 0; x < _this.modifyFields.length; x++) {
	                            if (!_this.modifyFields[x].ruleFn(tableData[j])) {
	                                continue;
	                            }
	                            if (_this.modifyFields[x].field == field.option.field) { //修改加载的数据
	                                td.html('<div class="kg-datagird-twrap ' + (field.option.newline ? 'kg-datagird-twrap-newline' : '') + '" title="' + _this.modifyFields[x].ruleFn(tableData[j]).replace(/\<.*?\>/g, ' ').trim().replace(' ', ' | ') + '">' + _this.modifyFields[x].ruleFn(tableData[j]) + '</div>');
	                                // td.find('.kg-datagird-twrap').html(_this.modifyFields[x].ruleFn(tableData[j])).attr('title',tableData[j][field.option.field] ? tableData[j][field.option.field] : '');
	                            }
	                        }
	                    }
	                })
	            }
	        },
	        updateTrHeight: function() {
	            var lheight = 0,
	                height = 0,
	                rheight = 0;
	            this.$tableContainer.find('tbody tr').height(0);
	            for (var i = 0; i < this.trNum; i++) {
	                height = this.$table.find('tbody tr').eq(i).height();
	                if (this.leftfields.length > 0) {
	                    lheight = this.$lefttable.find('tbody tr').eq(i).height();
	                    height = Math.max(lheight, height);
	                }
	                if (this.rightfields.length > 0) {
	                    rheight = this.$righttable.find('tbody tr').eq(i).height();
	                    height = Math.max(rheight, height);
	                }
	                if (height == 50) {
	                    continue;
	                }
	                if (this.leftfields.length > 0) {
	                    this.$lefttable.find('tbody tr').eq(i).height(height);
	                }
	                if (this.rightfields.length > 0) {
	                    this.$righttable.find('tbody tr').eq(i).height(height);
	                }
	                this.$table.find('tbody tr').eq(i).height(height);
	            }
	        },
	        setLoader: function(isShow) { // 设置table加载状态
	            if (isShow) {
	                if (!this.$loader) {
	                    this.$loader = $('<div class="kg-datagird-loader"><div class="kg-datagird-loader-icon"><i class="fa fa-spinner fa-spin fa-5x" style="color:#0dbbe5"></i></div></div>');
	                    this.$tableContainer.append(this.$loader);
	                }
	                this.$loader.fadeIn(200);
	            } else {
	                this.$loader.fadeOut(200);
	            }
	        },
	        getSelected: function() { //获取当前选中元素
	            var selecteds = [];

	            this.$tableContainer.find('.kungeekui-datagird-checkbox input[type=checkbox]').each(function() {
	                if ($(this).is(':checked')) {
	                    selecteds.push($(this).parents('tr').get(0).trData)
	                }
	            });
	            // this.$tbody.find('tr').each(function() {
	            //     if ($(this).find('.kungeekui-datagird-checkbox input[type=checkbox]').is(':checked')) {
	            //         selecteds.push(this.trData)
	            //     }
	            // })
	            return selecteds;
	        },
	        cancelSelected: function() { //取消选择
	            this.$tableContainer.find('.kg-checkbox input[type=checkbox]').prop('checked', false);
	        },
	        addExtraField: function(oneAddField) { //根据行内规则自定义增加列

	            var _this = this;
	            if (oneAddField) {
	                //oneAddField变形
	                var field = {
	                    title: oneAddField.title,
	                    option: {
	                        width: oneAddField.width,
	                        align: oneAddField.align,
	                        field: oneAddField.field,
	                        fixed: oneAddField.fixed,
	                        newline: oneAddField.newline,
	                    },
	                    ruleFn: oneAddField.ruleFn
	                }
	                if (oneAddField.fixed) { //如果要固定
	                    if (oneAddField.fixed == 'right') {
	                        if (oneAddField.index && oneAddField.index > 0 && oneAddField.index <= this.rightfields.length) { //如果有排序
	                            this.rightfields.splice(oneAddField.index - 1, 0, field);
	                        } else {
	                            this.rightfields.push(field);
	                        }
	                    } else {
	                        if (oneAddField.index && oneAddField.index > 0 && oneAddField.index <= this.leftfields.length) { //如果有排序
	                            this.leftfields.splice(oneAddField.index - 1, 0, field);
	                        } else {
	                            this.leftfields.push(field);
	                        }
	                    }
	                } else {
	                    if (oneAddField.index && oneAddField.index > 0 && oneAddField.index <= this.fields.length) { //如果有排序
	                        this.fields.splice(oneAddField.index - 1, 0, field);
	                    } else {
	                        this.fields.push(field);
	                    }
	                }

	            }
	            //更新table
	            //左边table
	            if (this.leftfields.length > 0) {
	                if (!this.$lefttable) {
	                    this.creatTable('left');
	                }
	                this.initThead('left');
	                this.createTbodyTr('left');
	            }
	            //左边table
	            if (this.rightfields.length > 0) {
	                if (!this.$righttable) {
	                    this.creatTable('right');
	                }
	                this.initThead('right');
	                this.createTbodyTr('right');
	            }

	            this.updateTableWidth();
	            this.initThead();
	            this.createTbodyTr();
	            this.trEvent();
	            _this.render();

	        },
	        createCopyThead: function(dir) {
	            var _this = this;
	            var dir = arguments[0] ? arguments[0] : '';
	            var table = this['$' + dir + 'table'];
	            var thead = table.find('thead');
	            var fields = this[dir + 'fields'];
	            if (!this['$' + dir + 'copyHead']) {
	                var fTable = $('<table>').addClass(table.attr('class')).addClass('kungeekui-datagrid-fixed-thead animated').css({ 'top': 0, 'left': 0 });
	                var fThead = thead.clone();
	                fTable.append(fThead);
	                this['$' + dir + 'copyHead'] = fTable;
	                table.before(this['$' + dir + 'copyHead']);
	                if (this.option.hasCheckBox && dir == 'left') { //如果有checkbox
	                    this['$' + dir + 'copyHead'].find('#kg-c-0').remove();
	                    this['$' + dir + 'copyHead'].find('thead tr th .kg-checkbox').eq(0).prepend(thead.find('#kg-c-0'));
	                }
	            }
	            if (thead.find('th').length != this['$' + dir + 'copyHead'].find('th').length) { //如果原表格列更新了
	                this['$' + dir + 'copyHead'].find('thead').remove();
	                this['$' + dir + 'copyHead'].append(thead.clone());
	            }

	        },
	        listenScorll: function() { //监控滚动
	            var _this = this;
	            //初始化的设置

	            var pTop = this.$tableContainer.offset().top;
	            var wTop = $(window).scrollTop();
	            var tHeight = this.$tableContainer.height() - (this.$tfoot ? this.$tfoot.height() + 18 : 0);

	            //监控tableC$tableContainer的滚动
	            this.scrollTop = 0;
	            this.$tableContainer.on('scroll.scroll', function(e) {

	                var thead = _this.$tableContainer.find('.kungeekui-datagrid-fixed-thead');
	                var sLeft = $(this).scrollLeft();
	                var sTop = $(this).scrollTop();
	                _this.scrollTop = sTop;
	                if (thead) {
	                    thead.css({
	                        top: sTop
	                    })
	                }
	            })

	            this.$tableWrap.on('scroll.scroll', function(e) {
	                var sLeft = $(this).scrollLeft();
	                var sTop = $(this).scrollTop();

	                if (sLeft > 0) {
	                    _this.$tableContainer.find('.left-table-fiexd').addClass('showShadow');
	                } else {
	                    _this.$tableContainer.find('.left-table-fiexd').removeClass('showShadow');
	                }
	                if (sLeft >= (_this.$table.width() - _this.$tableWrap.width())) {
	                    _this.$tableContainer.find('.right-table-fiexd').removeClass('showShadow');
	                } else {
	                    _this.$tableContainer.find('.right-table-fiexd').addClass('showShadow');
	                }
	            })


	            //监控document的滚动
	            $(document).on('scroll.scroll', function(e) {
	                var thead = _this.$tableContainer.find('.kungeekui-datagrid-fixed-thead');
	                wTop = $(window).scrollTop();
	                tHeight = _this.$tableContainer.height() - (_this.$tfoot ? _this.$tfoot.height() + 18 : 0);
	                pTop = _this.$tableContainer.offset().top;
	                if (_this.option.fixedThead) { //如果固定表头
	                    if ((wTop - pTop) > 0 && (wTop - pTop) < tHeight && thead) {
	                        thead.addClass('active');
	                        thead.css('top', (wTop - pTop) > 0 ? (wTop - pTop + _this.scrollTop) : 0)
	                    } else if ((wTop - pTop) <= 0 && thead) {
	                        thead.removeClass('active');
	                        thead.css('top', _this.scrollTop)
	                    }
	                }
	            })
	        },
	        addFieldDragBtn: function() { //列宽度拖动
	            var _this = this;
	            var table = this.$table;
	            if (this.$copyHead) { //如果固定表头
	                var table = this.$copyHead;
	            }
	            table.find('thead .kungeekui-datagrid-dragBtn').remove();
	            for (var i = 0; i < table.find('th').length; i++) {
	                var dragBtn = $('<div class="kungeekui-datagrid-dragBtn"></div>');
	                table.find('th').eq(i).append(dragBtn);
	            }
	            if (!this.$tableDragLine) {
	                this.$tableDragLine = $('<div class="kungeekui-datagrid-dragLine">');
	                this.$tableWrap.append(this.$tableDragLine)
	            }
	            //添加事件


	            table.find('.kungeekui-datagrid-dragBtn').each(function(index) {
	                $(this).off('mousedown.dragBtn');
	                $(this).off('mouseup.dragBtn');
	                $(this).on({
	                    'mousedown.dragBtn': function(e) {
	                        e.stopPropagation();
	                        var el = $(this);
	                        var tw = table.outerWidth();
	                        var th = el.parent('th');
	                        var thw = th.outerWidth();
	                        var line = _this.$tableDragLine;
	                        line.fadeIn(200);
	                        $(document).on('mousemove.drag', function(e) {
	                            e.preventDefault();
	                            e.stopPropagation();
	                            var ex = e.pageX;
	                            var lineLeft = e.pageX > (th.offset().left + _this.option.minFieldWidth) ? e.pageX : (th.offset().left + _this.option.minFieldWidth);
	                            line.css('left', lineLeft - table.offset().left);
	                        });
	                        $(document).on('mouseup.drag', function(e) {
	                            line.fadeOut(200);
	                            var width = line.offset().left - th.offset().left;
	                            th.css('width', width);
	                            table.css('width', tw + (width - thw));
	                            if (_this.$copyHead) {
	                                _this.$thead.find('th').eq(index).css('width', width)
	                                _this.$table.css('width', tw + (width - thw));
	                            }
	                            _this.updateTrHeight();
	                            if (_this.$tableWrap.scrollLeft() >= (_this.$table.width() - _this.$tableWrap.width())) {
	                                _this.$tableContainer.find('.right-table-fiexd').removeClass('showShadow');
	                            } else {
	                                _this.$tableContainer.find('.right-table-fiexd').addClass('showShadow');
	                            }
	                            $(document).off('mouseup.drag');
	                            $(document).off('mousemove.drag');
	                        });
	                    },
	                    'mouseup.dragBtn': function(e) {
	                        e.stopPropagation();
	                        $(document).off('mouseup.drag');
	                        $(document).off('mousemove.drag');
	                    }
	                })
	            })

	            // table.find('.kungeekui-datagrid-dragBtn').each(function(index) {
	            //     $(this).off('mousedown.dragBtn');
	            //     $(this).off('mouseup.dragBtn');
	            //     $(this).on({
	            //         'mousedown.dragBtn': function(e) {
	            //             e.stopPropagation();
	            //             var el = $(this);
	            //             var thW = el.parent('th').outerWidth();
	            //             var tw = table.outerWidth();
	            //             var sx = e.pageX;
	            //             el.parent('th').addClass('isDraging');
	            //             $(document).on('mousemove.drag', function(e) {
	            //                 var ex = e.pageX;
	            //                 var width = (thW + (ex - sx)) < 40 ? 40 : (thW + (ex - sx));
	            //                 var gw = width - thW;
	            //                 if ((thW + (ex - sx)) < 40) {
	            //                     return;
	            //                 }
	            //                 el.parent('th').css('width', width);
	            //                 table.css('width', tw + gw);
	            //                 if (_this.$copyHead) {
	            //                     _this.$thead.find('th').eq(index).css('width', width)
	            //                     _this.$table.css('width', tw + gw);
	            //                 }
	            //                 _this.updateTrHeight();
	            //             });
	            //         },
	            //         'mouseup.dragBtn': function(e) {
	            //             e.stopPropagation();
	            //             $(document).off('mousemove.drag');
	            //             $('.isDraging').removeClass('isDraging');
	            //         }
	            //     })
	            // })
	            // $(document).off('mouseup.drag');
	            // $(document).on('mouseup.drag', function(e) {
	            //     $(document).off('mousemove.drag');
	            //     $('.isDraging').removeClass('isDraging');
	            // });
	        },
	        addFieldOrderBtn: function() {
	            var _this = this;
	            var table = this.$table;
	            if (this.$copyHead) { //如果固定表头
	                table = this.$copyHead;
	            }
	            table.find('thead').off('mousedown.order')
	            table.find('thead').on('mousedown.order', 'th.order', function(e) {
	                e.stopPropagation();
	                var orderName = _this.fields[e.currentTarget.cellIndex].option.orderName;
	                if (!orderName) return;
	                if (!_this.orderRule) {
	                    _this.orderRule = {
	                        rule: 0,
	                        orderName: orderName,
	                        orderDes: ['', 'desc', 'asc']
	                    }
	                }
	                if (_this.orderRule.orderName != orderName) {
	                    _this.orderRule.rule = 0;
	                    _this.orderRule.orderName = orderName;
	                }
	                table.find('thead th').removeClass('orderUp orderDown');
	                if (_this.orderRule.rule == 1) {
	                    $(this).addClass('orderUp');
	                    $(this).removeClass('orderDown');
	                    _this.orderRule.rule = 2;
	                    //_this.render();
	                    _this.reloadUrl(_this.option.source, true);
	                    return;
	                }
	                if (_this.orderRule.rule == 2) {
	                    $(this).removeClass('orderDown');
	                    $(this).removeClass('orderUp');
	                    // $(this).removeClass('order');
	                    _this.orderRule.rule = 0;
	                    //_this.render();
	                    _this.reloadUrl(_this.option.source, true);
	                    return;
	                }
	                if (_this.orderRule.rule == 0) {
	                    $(this).addClass('orderDown');
	                    $(this).removeClass('orderUp');
	                    _this.orderRule.rule = 1;
	                    //_this.render();
	                    _this.reloadUrl(_this.option.source, true);
	                    return;
	                }

	            })
	        },
	        modifyField: function() { //修改列
	            this.render();
	        },
	        gotoPage: function(pageIndex) { //跳转到某页
	            var _this = this;
	            this.getSourceData(pageIndex, function() {
	                _this.render();
	            })
	        },
	        getPageSize: function() { //获取当前显示多少条
	            return this.pageSize;
	        },
	        getTotalData: function() { //获取总共多少条数据
	            return this.pagedResult.total;
	        },
	        getPage: function() { //获取当前页
	            return this.page
	        },
	        refresh: function() { //刷新本页
	            var _this = this;
	            if (this.option.source) {
	                this.getSourceData(this.page, function() {
	                    _this.render();
	                })
	            } else {
	                _this.render()
	            }
	        },
	        loadData: function(url) { //加载数据
	            var _this = this;
	            this.option.source = url;
	            this.getSourceData(1, function() {
	                _this.render();
	            });
	        },
	        reloadUrl: function(url, goToNowPage) {
	            this.option.source = url;
	            if (goToNowPage) {
	                this.gotoPage(this.page);
	                return;
	            }
	            this.gotoPage(1);
	        },
	        putData: function(data) { //将数据替换当前页的数据
	            this.trNum = data.length;
	            this.imposedTrNum = true;
	            if (this.readedTableData.length == 0) {
	                var tableData = {
	                    page: 1,
	                    tableData: data
	                }
	                this.readedTableData.push(tableData);
	            } else {
	                for (var i = 0; i < this.readedTableData.length; i++) {
	                    if (this.readedTableData[i].page == this.page) {
	                        this.readedTableData[i].tableData = data;
	                    }
	                }
	            }

	            this.render();
	        },
	        mask: function(stat) {
	            if (!this.$mask) {
	                this.$mask = $('<div class="kg-datagird-mask">');
	                this.$tableContainer.append(this.$mask);
	            }
	            if (stat == 'show') {
	                this.$mask.stop().fadeIn();
	            } else if (stat == 'hide') {
	                this.$mask.stop().fadeOut();
	            }
	        },
	        listen: function(event, fn) { //事件监听
	            if (typeof event == 'string' && typeof fn == 'function') {
	                if (!this.handle[event]) {
	                    this.handle[event] = [];
	                }
	                this.handle[event].push(fn)
	            }
	        },
	        fire: function(event, data) {
	            //rendered 渲染完成后
	            if (!this.handle[event]) {
	                return;
	            }
	            for (var i = 0; i < this.handle[event].length; i++) {
	                this.handle[event][i](data);
	            }
	        }
	    }

	    //datagrid 可使用方法：
	    $.extend(true, $.fn, {
	        getSelected: function() { //获取表格当前选中项目
	            return this.get(0).datagrid ? this.get(0).datagrid.getSelected() : this;
	        },
	        cancelSelected: function() { //取消表格数据中的选择
	            return this.each(function() {
	                this.datagrid ? this.datagrid.cancelSelected() : this;
	            })
	        },
	        addField: function(option, ruleFn, index) { //添加列
	            if (!option || !ruleFn || !$.isFunction(ruleFn)) {
	                return;
	            }
	            var index = arguments[2] ? arguments[2] : 0;
	            var oneAddField = {
	                title: '',
	                ruleFn: ruleFn,
	                field: '',
	                fixed: false,
	                align: 'center',
	                width: 'initial',
	                newline: false,
	                index: index,
	                rule: null
	            };
	            if ($.isPlainObject(option)) {
	                $.extend(true, oneAddField, option)
	            } else if ($.type(option) == "string") {
	                oneAddField.title = option;
	            } else {
	                return;
	            }
	            return this.each(function() {
	                this.datagrid ? this.datagrid.addExtraField(oneAddField) : this;
	            })
	        },
	        modifyField: function(field, ruleFn) { //列修改 field为checkbox 则修改checkbox列
	            if (!field || !ruleFn || !$.isFunction(ruleFn)) {
	                return;
	            }
	            return this.each(function() {
	                if (!this.datagrid) {
	                    return this;
	                }
	                var oneModify = {
	                    field: field,
	                    ruleFn: ruleFn
	                }
	                if (this.datagrid.modifyFields.length == 0) {
	                    this.datagrid.modifyFields.push(oneModify);
	                    return;
	                }
	                for (var i = 0; i < this.datagrid.modifyFields.length; i++) {
	                    if (this.datagrid.modifyFields[i].field == field) {
	                        this.datagrid.modifyFields[i] = oneModify;
	                    } else {
	                        this.datagrid.modifyFields.push(oneModify);
	                    }
	                }
	                this.datagrid.modifyField();
	            })
	        },
	        gotoPage: function(pageIndex) { //跳转到某页
	            return this.each(function() {
	                this.datagrid ? this.datagrid.gotoPage(pageIndex) : this;
	            })
	        },
	        getPage: function(pageIndex) { //获取当前是第几页
	            return this.get(0).datagrid ? this.get(0).datagrid.getPage() : this;
	        },
	        getPageSize: function() { //获取当前显示多少条
	            return this.get(0).datagrid ? this.get(0).datagrid.getPageSize() : this;
	        },
	        getTotalData: function() { //获取总共多少条数据
	            return this.get(0).datagrid ? this.get(0).datagrid.getTotalData() : this;
	        },
	        loadData: function(url) { //加载url中的数据
	            return this.each(function() {
	                this.datagrid ? this.datagrid.loadData(url) : this;
	            })
	        },
	        reloadUrl: function(url) { //更换url 并且重载
	            return this.each(function() {
	                this.datagrid ? this.datagrid.reloadUrl(url) : this;
	            })
	        },
	        putData: function(data) { //把数组数据填充到表格中
	            return this.each(function() {
	                this.datagrid ? this.datagrid.putData(data) : this;
	            })
	        },
	        refresh: function() { //刷新表格
	            return this.each(function() {
	                this.datagrid ? this.datagrid.refresh() : this;
	            })
	        },
	        mask: function(stat) { //创建遮罩('show'/'hide')
	            return this.each(function() {
	                this.datagrid ? this.datagrid.mask(stat) : this;
	            })
	        },
	        listen: function(event, fn) { //事件监听
	            return this.each(function() {
	                this.datagrid ? this.datagrid.listen(event, fn) : this;
	            })
	        },
	        updateTableWidth: function() { //更新表格宽度
	            return this.each(function() {
	                this.datagrid ? this.datagrid.updateTableWidth() : this;
	            })
	        }
	    })


	    //DateSelect
	    kungeekui.DateSelect = function(option) {

	        if (!option.target || option.target.get(0).tagName != 'INPUT') {
	            throw new Error(
	                '实例化 DateSelect 必须传入 target 参数，target为$(input标签选择器字符串)');
	            return;
	        }
	        var _this = this;
	        this.defaultOption = {
	            selectType: ['Y', 'S', 'M'],
	            format: 'YYYY-MM-DD',
	            gap: ' 至 ',
	            formatSimple: true,
	            readonly: true, //不许修改
	        }


	        this.option = $.extend(false, {}, this.defaultOption, option);
	        //转为大写
	        this.option.selectType.map(function(val, i) {
	            _this.option.selectType[i] = val.toLocaleUpperCase();
	        })
	        return this.init();
	    }
	    kungeekui.DateSelect.prototype = {
	        init: function() { //初始化
	            this.$input = this.option.target;
	            this.$input.get(0).exist = true;
	            this.$input.get(0).dateSelect = this; //dom对象引用到实例化dateSelect
	            this.page = 0;
	            this.setDefualtData(); //设置初始数据
	            this.createBoard(); //创建面板
	            this.initBoardTop(); //初始化类型选择面板
	            this.setBoardMiddle(this.nowYear); //初始化年份面板
	            this.initBoardContent(); //初始化内容
	            this.dateVal = {}; //输出的值
	            this.transformInputVal();
	            if (this.option.readonly) { //是否不允许在input中修改值
	                this.$input.attr('readonly', true)
	            }
	        },
	        transformInputVal: function() { //转换input的值
	            var val = this.$input.val();
	            if (!val) return;
	            if (this.option.formatSimple) {
	                val = val.replace(/([0-9]{4,4})[\年\-\/\s]*([0-9]{0,2})[\月\-\/\s]*([0-9]{0,2})[\日\s]*(([\至]+)[\s]*([0-9]{2,4})[\年\-\/\s]*([0-9]{1,2})[\月\-\/\s]*([0-9]{0,2})[\日]*){0,1}/g, function(word, $1, $2, $3, $4, $5, $6, $7, $8) {
	                    return ($1 ? $1 : '') + ($2 ? '-'.concat($2) : '') + ($3 ? '-'.concat($3) : '') + ($5 ? ('至' + ($6 ? $6 : '') + ($7 ? '-'.concat($7) : '') + ($8 ? '-'.concat($8) : '')) : '');
	                })
	            }
	        },
	        setDefualtData: function() {
	            this.nowTime = moment().format('YYYY-MM-DD');
	            this.nowYear = moment().format('YYYY') - 0;
	            this.nowMonth = moment().format('MM') - 0;
	            this.nowSeason = moment().format('Q') - 0;
	            this.nowDay = moment().date() - 0;
	        },
	        createBoard: function() {
	            var _this = this;
	            if (!this.$board) {
	                this.$board = $('<div class="kg-dateSelect-board">')
	                this.$boardTop = $('<div class="board-top"><div class="board-type-cells"></div></div>');
	                this.$boardMiddle = $('<div class="board-middle"><p class="year"> 年</p></div>');
	                this.$boardMiddleWeek = $('<div class="board-middle week"><label>日</label><label>一</label><label>二</label><label>三</label><label>四</label><label>五</label><label>六</label></div>');
	                this.$boardContent = $('<div class="board-content">');
	                this.$prev = $('<div class="board-tab board-tab-prev">«</div>')
	                this.$cells = $('<div class="board-cells">')
	                this.$next = $('<div class="board-tab board-tab-next">»</div>')
	                this.$boardContent.append(this.$prev);
	                this.$boardContent.append(this.$cells);
	                this.$boardContent.append(this.$next);
	                this.$board.append(this.$boardTop);
	                this.$board.append(this.$boardMiddle);
	                this.$board.append(this.$boardMiddleWeek);
	                this.$board.append(this.$boardContent);
	                $('body').append(this.$board);
	                this.setBoardPosition();
	                this.setEvent();
	                $(window).on('scroll', function() { //监控位移定位
	                    _this.setBoardPosition();
	                })
	                $(window).resize(function() { //监控位移定位
	                    _this.setBoardPosition();
	                })
	            }
	        },
	        setEvent: function() {
	            var _this = this;
	            this.$board.on('click', function(e) {
	                e.stopPropagation();
	            })

	            this.selectEvent();

	            this.$input.on('focus', function() {
	                    _this.setBoardPosition();
	                    _this.$board.show();
	                })
	                // this.$input.on('blur', function() {
	                //     _this.$board.hide();
	                // })
	            this.$input.on('click', function(e) {
	                e.stopPropagation()
	            })
	            this.$board.on('click', function(e) {
	                e.stopPropagation()
	            })

	            $(document).on('click', function() {
	                _this.$board.hide();
	            })
	        },
	        setBoardPosition: function() { //设置面板位置
	            this.$board.css({
	                top: this.$input.offset().top + this.$input.outerHeight(),
	                left: this.$input.offset().left,
	            })
	        },
	        selectEvent: function() {
	            var _this = this;
	            this.$cells.on('click', '.board-cell:not(.board-cell-disabled)', function(e) {
	                _this.$cells.find('.board-cell').removeClass('active');
	                $(this).addClass('active');
	                _this.pickData(e.target.innerHTML.replace(/[^\d]/g, ''));
	            });
	        },
	        pickData: function(val) {
	            var startDate = '',
	                endDate = '',
	                format = this.option.format;

	            if (this.type == 'Y') {
	                startDate = moment(val.toString());
	                endDate = moment(val.toString()).endOf("year");
	                this.$input.val(val + '年');
	            }
	            if (this.type == 'S') {
	                startDate = moment(this.nowYear + this.page + '-' + (val * 3 - 2));
	                endDate = moment(this.nowYear + this.page + '-' + (val * 3)).endOf("month");
	                this.$input.val(this.nowYear + this.page + '年第' + val + '季度');
	            }
	            if (this.type == 'M') {
	                startDate = moment(this.nowYear + this.page + '-' + val);
	                endDate = moment(this.nowYear + this.page + '-' + val).endOf("month");
	                this.$input.val(startDate.format('YYYY年M月'));
	            }
	            if (this.type == 'D') {
	                var month = moment(this.nowTime);
	                if (this.page > 0) {
	                    month.add(this.page, 'M');
	                } else if (this.page < 0) {
	                    month.subtract(~this.page + 1, 'M');
	                } else {
	                    month = moment(this.nowTime);
	                }
	                startDate = moment(month.format('YYYY-MM') + '-' + val);
	                endDate = startDate;
	                this.$input.val(startDate.format('YYYY年M月D日'));
	            }
	            if (!this.option.formatSimple) { //如果需要具体显示
	                if (startDate.format(format) != endDate.format(format)) {
	                    this.$input.val(startDate.format(format) + this.option.gap + endDate.format(format));
	                } else {
	                    this.$input.val(startDate.format(format));
	                }
	            }
	            this.$board.hide();
	            this.dateVal = {
	                val: this.$input.val(),
	                startDate: startDate.format('YYYY-MM-DD'),
	                endDate: endDate.format('YYYY-MM-DD'),
	                type: this.type
	            }
	            this.$input.trigger('change', this.dateVal);
	            //this.$board.hide();
	        },
	        initBoardTop: function() {
	            var _this = this;
	            if (this.option.selectType.length == 0) {
	                this.option.selectType = ['Y', 'S', 'M'];
	            }
	            this.option.selectType.map(function(item) {
	                var type, text, item = item;
	                if (item == "Y") {
	                    type = 'Y';
	                    text = '年';
	                }
	                if (item == "S") {
	                    type = 'S';
	                    text = '季';
	                }
	                if (item == "M") {
	                    type = 'M';
	                    text = '月';
	                }
	                if (item == "D") {
	                    type = 'D';
	                    text = '日';
	                }
	                if (!_this[type + 'Cell']) {
	                    _this[type + 'Cell'] = $('<a href="javascript:void(0)" class="btn board-type-cell">' + text + '</a>');
	                    _this.$boardTop.find('.board-type-cells').append(_this[type + 'Cell']);
	                    _this[type + 'Cell'].on('click', function() {
	                        _this.$boardTop.find('.board-type-cell').removeClass('active');
	                        $(this).addClass('active');
	                        _this.tabMode(type);
	                        _this.setPNBtn(type);
	                    })
	                }
	            })
	            this.$boardTop.find('.board-type-cell').eq(0).addClass('active');
	            this.setPNBtn(this.option.selectType[0]);
	            this.type = this.option.selectType[0];

	        },
	        setBoardMiddle: function(year) {
	            this.$boardMiddle.find('p').html(year + ' 年');
	        },
	        initBoardContent: function() {
	            this.tabMode(this.option.selectType[0])
	        },
	        tabMode: function(type, page) { //切换模式
	            var cellSum = 12;
	            var page = page ? page : 0; //第几页，默认第0页
	            this.type = type;
	            this.$cells.removeClass('animated slideInLeft slideInRight');
	            if (!this.$cellsCopy) {
	                this.$cellsCopy = this.$cells.clone();
	                this.$cellsCopy.addClass('copy');
	                this.$cells.after(this.$cellsCopy);
	            }
	            this.$cellsCopy.removeClass('animated fadeOutLeft fadeOutRight');
	            this.$cellsCopy.css('left', this.$prev.outerWidth());
	            this.$cellsCopy.empty().html(this.$cells.html());

	            this.$cells.hide();
	            this.$cellsCopy.hide();
	            if (this.page >= page) {
	                this.$cells.addClass('animated slideInRight')
	                this.$cellsCopy.addClass('animated fadeOutLeft')
	            } else {
	                this.$cells.addClass('animated slideInLeft')
	                this.$cellsCopy.addClass('animated fadeOutRight')
	            }
	            this.$cells.empty();
	            this.$cells.show();
	            this.$cellsCopy.show();

	            this.setBoardMiddle(this.nowYear + page);
	            this.$boardMiddleWeek.hide();
	            if (type == 'Y') {
	                this.$boardMiddle.hide();
	                var dIndex = 6; //今年默认位置
	                for (var i = 1; i <= cellSum; i++) {
	                    var text = (this.nowYear + (i - 6));
	                    var cell = $('<a href="javascript:void(0)" class="btn board-cell">' + (text + (page * cellSum)) + '</a>');
	                    if ((text + (page * cellSum)) == this.nowYear) {
	                        cell.addClass('borad-cell-now');
	                    }
	                    this.$cells.append(cell);
	                }
	            }
	            if (type == 'S') {
	                this.$boardMiddle.show();
	                cellSum = 4;
	                for (var i = 1; i <= cellSum; i++) {
	                    var cell = $('<a href="javascript:void(0)" class="btn board-cell board-cell-big"> 第 ' + i + ' 季度 </a>');
	                    if (i == this.nowSeason && page == 0) {
	                        cell.addClass('borad-cell-now');
	                    }
	                    this.$cells.append(cell);
	                }
	            }
	            if (type == 'M') {
	                this.$boardMiddle.show();
	                cellSum = 12;
	                for (var i = 1; i <= cellSum; i++) {
	                    var cell = $('<a href="javascript:void(0)" class="btn board-cell">' + i + '月</a>');
	                    if (i == this.nowMonth && page == 0) {
	                        cell.addClass('borad-cell-now');
	                    }
	                    this.$cells.append(cell);
	                }
	            }
	            if (type == 'D') {
	                this.$boardMiddle.show();
	                this.$boardMiddleWeek.show();
	                var month = moment(this.nowTime);
	                var dayNums, fday;
	                if (page > 0) {
	                    month.add(page, 'M');
	                } else if (page < 0) {
	                    month.subtract(~page + 1, 'M');
	                } else {
	                    month = moment(this.nowTime);
	                }
	                fday = month.startOf('month').days() == 0 ? 7 : month.startOf('month').days();
	                dayNums = month.daysInMonth();
	                cellSum = 42;
	                this.$boardMiddle.find('p').html(month.format('YYYY年MM月'));
	                for (var i = 0; i < cellSum; i++) {
	                    var cell;
	                    if (i < fday || i > (dayNums + fday - 1)) {
	                        cell = $('<a href="javascript:void(0)" class="btn board-cell board-cell-sm board-cell-disabled"></a>');
	                    } else {
	                        cell = $('<a href="javascript:void(0)" class="btn board-cell board-cell-sm">' + (i + 1 - fday) + '</a>');
	                    }

	                    if (i == this.nowDay && page == 0) {
	                        cell.addClass('borad-cell-now');
	                    }
	                    this.$cells.append(cell);
	                }
	            }

	            this.page = page;
	        },
	        setPNBtn: function(type) {
	            var _this = this;
	            this.$prev.off('click');
	            this.$next.off('click');
	            var cellSum = 12;
	            if (type == 'Y') {
	                var yearPage = 0;
	                this.$prev.on('click', function() {
	                    yearPage -= 1;
	                    _this.tabMode(type, yearPage);
	                })
	                this.$next.on('click', function() {
	                    yearPage += 1;
	                    _this.tabMode(type, yearPage);
	                })
	            }
	            if (type == 'S' || type == 'M') {
	                var yearPage = 0;
	                this.$prev.on('click', function() {
	                    yearPage -= 1;
	                    _this.tabMode(type, yearPage);
	                })
	                this.$next.on('click', function() {
	                    yearPage += 1;
	                    _this.tabMode(type, yearPage);
	                })
	            }
	            if (type == 'D') {
	                var monthPage = 0;
	                this.$prev.on('click', function() {
	                    monthPage -= 1;
	                    _this.tabMode(type, monthPage);
	                })
	                this.$next.on('click', function() {
	                    monthPage += 1;
	                    _this.tabMode(type, monthPage);
	                })
	            }
	        }
	    }

	    //jquery 扩展
	    $.extend(true, $.fn, {
	        dateSelect: function(task) {
	            if (this.get(0) && this.get(0).exist) {
	                return;
	            }
	            if (!moment) {
	                throw new Error('dateSelect 依赖于 moment.js');
	                return;
	            }
	            return this.each(function() {
	                var option = {
	                    target: $(this),
	                    task: task ? task : '',
	                }
	                if ($(this).attr('kg-select-type')) {
	                    option.selectType = $(this).attr('kg-select-type').split('')
	                }
	                if ($(this).attr('kg-select-format')) {
	                    option.format = $(this).attr('kg-select-format')
	                }
	                if ($(this).attr('kg-select-formatSimple')) {
	                    option.formatSimple = $(this).attr('kg-select-formatSimple').toBool()
	                }
	                new DateSelect(option)
	            })
	        },
	        getDate: function() { //获取日期插件的日期，如果没有值则返回{}
	            if (!this.get(0).dateSelect) {
	                return '';
	            }
	            return this.get(0).dateSelect.dateVal
	        }
	    })

	    // ------------------------公共函数/扩展
	    //扩展
	    // 字符串扩展，属性字符串转对象 规则 : 'width':'200px'  -> {width:'200px'}
	    String.prototype.toObject = function() {
	        return JSON.parse('{' + this.replace(/\s*['"]*([^'":;\s]*)['"]*\s*:+\s*['"]*([^'":;\s]*)['"]*\s*;*/g, '"$1":"$2",').replace(/,{1}$/g, '') + '}');
	    };

	    // 字符串 toBool 说明："false" to false
	    String.prototype.toBool = function() {
	        return (/^true$/i).test(this);
	    };

	    //判断是否email   
	    String.prototype.isEmail = function() { return /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(this); }

	    //检查电话号码   
	    String.prototype.isPhoneCall = function() { return /(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^[0−9]3,4[0-9]{3,8}$)|(^0{0,1}1[0-9]{10}$)/.test(this); }

	    //金额字符串处理
	    String.prototype.toMoney = function() {
	        var temp = /[0-9]+(\.[0-9]+){0,1}/.exec(this);
	        temp = (str = (temp ? temp[0] : '0')).split('.');
	        !!temp[1] ? temp[1].length < 2 && (str += '0') : str += '.00';
	        var array = [];
	        for (var i = 0; i < temp[0].length; i++) {
	            array.push(str[i]);
	        }
	        var result = [];
	        array.reverse().forEach(function(s, index) {
	            if (index > 0 && index % 3 == 0)
	                result.push(',');
	            result.push(s);
	        });
	        return str.replace(/^[0-9]+/g, result.reverse().join(''));
	    }

	    //函数
	    window.redirectTab = function(name, url) {
	        if (!name) {
	            return;
	        }
	        if (!window.top.$) { return }
	        var $$ = window.top.$;
	        $$('.submenu-label').each(function() {
	            if ($(this).text() == name) {
	                var li = $(this).parent('a').parent('li');
	                $$('.openable').removeClass('open');
	                $$('.openable .submenu').hide();
	                $$('.openable .submenu').find('li').removeClass('active');
	                li.parent('ul').show();
	                li.parent('ul').parent('li').addClass('open');
	                li.addClass('active');
	                if (!url) { li.trigger('click'); }
	                return
	            }
	        })
	        if (url) {
	            window.location.href = url
	        }
	    }

	    // 默认执行方法
	    // 暴露kungeekui
	    if (!window.kungeekui) {
	        window.kungeekui = kungeekui;
	        $.extend(true, window, kungeekui);
	        // 默认触发
	        // datagrid
	        $('table.kungeekui-datagrid').each(function() {
	            new Datagrid({
	                target: $(this)
	            })
	        })

	        $(document).ready(function() {
	            if (!window.moment) { return }
	            $('input.kg-dateSelect[type="text"]').dateSelect();
	        })
	    }



	})(jQuery)